(function($){
  var keyword = "";

  var showBottomMsg = function(msg){
	  var $msg = $("#pop-msg"); 
	  if((msg==null)||(msg=="")){
		  msg="返回错误，错误信息为空";
	  }
	  $msg.html(msg);
  	if($msg.hasClass("am-hide")){
  		$msg.removeClass("am-hide");
    } 
  }
  
  var hideBottomMsg = function(){
	  var $msg = $("#pop-msg"); 
		
		if(!$msg.hasClass("am-hide")){
    		$msg.addClass("am-hide");
    	}
  }

  var showResult = function(returnData){
    var groupInfo = returnData.groupInfo;
    if(!groupInfo || !groupInfo.grpName){
      showLoadingBar($("#loadingbar"),true,true,"该号码非集团成员，不能查询！");
      return;
    }

    window.location.href="general_member_list.html" + "?" + getParams() + "&grpName=" + encodeURIComponent(groupInfo.grpName) + "&phone=" + keyword;
  };
 
  var qryUnit = function(){
    var params ={"token":getToken(),"staffNo":getParamValue("EmpCode"),"passUrl":"phoneNo="+keyword};
    console.log("request:"+JSON.stringify(params));
    var reqUrl = Constants.rpcEsopHost+"qryUnitByPhoneNo";

    sendWsPostAjax(params,reqUrl,showResult,"loadingbar");

    // $.ajax({
    //   type: "post",
    //   contentType: "application/json",
    //   data: JSON.stringify(params),
    //   url: Constants.rpcEsopHost+"qryUnitByPhoneNo",
    //   dataType: "json",
    //   async: true,
    //   headers: {
    //   'token': getParamValue('token'),
    //   'saleType': getParamValue('saleType')
    // },
    // success: function(data) {
    //   if (data.ResultCode === 1009) {
    //     alert('登陆超时，请重新登录！');
    //     jumpToSignin();
    //     return;
    //   }
    //       console.log(data);
    //       var returnData = data.return;
    //       if(data.rtnCode!=1000){
    //         showLoadingBar($("#loadingbar"),true,true,data.rtnMsg);
    //         console.log("获取RPC接口返回失败！code:"+data.rtnCode);
    //         return;
    //       }
    //       if(returnData.resultCode!="00"){
    //         showLoadingBar($("#loadingbar"),true,true,returnData.resultDesc);
    //         console.log("获取信息接口返回失败！code:"+returnData.resultCode);
    //         return;
    //       }
          
    //       showResult(returnData,phone);
    //   },
    //   error : function(textStatus) {
    //     showLoadingBar($("#loadingbar"),true,true,"服务器异常，请联系管理员！");
    //     console.info("request error:");
    //   }
    // });
  };
  /**
  封装搜索条数据
  */
  var getSearchObj = function(){
    var obj = {};
    obj.keywordId = "keyword";
    obj.searchBtnId = "search_button";
    obj.searchPlaceholder = "请输入手机号码";

    return obj;
  }

  $(function(){
    showLoadingBar($("#loadingbar"),true,true,"提示：可以查询余额、营销活动、业务量！");
    //显示搜索条
    showItem(getSearchObj(),"search-tpl");

  	$('#search_button').click(function() {
      //hideBottomMsg();
      //showLoadingBar($('#loadingbar'),true);
  		keyword = $("#keyword").val();
      var reg = Constants.cmccMobileReg;
      if(!keyword){
        alert("手机号不能为空！");
        return;
      }
      if(!reg.test(keyword)){
        alert("请填写正确的中移手机号码！");
        return;
      }

      showLoadingBar($("#loadingbar"),true,false,"正在校验号码的集团归属信息……");
  		qryUnit();
  	});
	
  });

})(jQuery);
